package com.hixtrip.sample.infra.db.convertor;

import com.hixtrip.sample.domain.order.model.Order;
import com.hixtrip.sample.infra.db.dataobject.OrderEntity;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
 * DO对像 -> 领域对象转换器
 * todo 自由实现
 */
//@Mapper
public interface OrderDOConvertor {
//    OrderDOConvertor INSTANCE = Mappers.getMapper(OrderDOConvertor.class);
    AtomicLong autoId =  new AtomicLong(1);
    static OrderEntity orderEntityBuild(Order order){

        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setOrderId(autoId.incrementAndGet());
        orderEntity.setOrderNumber(Long.valueOf(order.getId()));
        orderEntity.setSkuId(Long.valueOf(order.getSkuId()));
        orderEntity.setUserId(Long.valueOf(order.getUserId()));
        orderEntity.setAmount(order.getAmount());
        orderEntity.setOrderStatus(0);
        orderEntity.setRemark("无");
        orderEntity.setOrderAmount(order.getMoney());
        orderEntity.setIsEvaluated(0);
        orderEntity.setOrderStatus(Integer.valueOf(order.getPayStatus()));
        return orderEntity;
    }
}
